<template>
  <view
    class="mask"
    :class="mask == 'true' || mask == true ? 'mask-show' : ''"
    @click="Mclose"
    v-if="show"
    @touchmove.stop.prevent="preventTouchMove"
  >
    <!-- 加载动画开始 -->
    <view class="loading-21">
      <view></view>
      <view></view>
      <view></view>
      <view></view>
      <view></view>
      <view></view>
    </view>
    <!-- 加载动画结束 -->
    <view class="title">{{ text }}</view>
  </view>
</template>

<script setup>
import { ref, computed } from 'vue'
import { useCounterStore } from '@/store/counter.js'

const props = defineProps({
  text: String,
  mask: [Boolean, String],
  click: [Boolean, String]
})

const store = useCounterStore()
const show = computed(() => store.showLoading)

// 阻止用户滚动
const preventTouchMove = () => {
  console.log('stop user scroll it!')
}

// 关闭加载动画
const Mclose = () => {
  if (props.click === 'false' || props.click === false) {
    store.showLoading = false
  }
}

// 手动打开加载动画
const open = () => {
  store.showLoading = true
}

// 手动关闭加载动画
const close = () => {
  store.showLoading = false
}
</script>

<style>
.mask {
  position: fixed;
  z-index: 99999;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  height: 100vh;
  width: 100vw;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}
.mask.mask-show {
  background: rgba(7, 17, 27, 0.3);
}
.title {
  color: #fff;
  font-size: 28upx;
}

.loading-21 view {
  width: 40upx;
  height: 40upx;
  border-radius: 20upx;
  backface-visibility: hidden;
  position: absolute;
  animation-name: move;
  animation-timing-function: cubic-bezier(0.4, 0, 1, 0.8);
  animation-iteration-count: infinite;
  animation-duration: 3s;
  top: calc(50% - 20upx);
  left: 50%;
  transform-origin: -20upx center;
}
.loading-21 view:nth-child(1) {
  background: #226b80;
  animation-delay: -0.5s;
  opacity: 0;
}
.loading-21 view:nth-child(2) {
  background: #226b80;
  animation-delay: -1s;
  opacity: 0;
}
.loading-21 view:nth-child(3) {
  background: #35b0ab;
  animation-delay: -1.5s;
  opacity: 0;
}
.loading-21 view:nth-child(4) {
  background: #c5f0a4;
  animation-delay: -2s;
  opacity: 0;
}
.loading-21 view:nth-child(5) {
  background: #226b80;
  animation-delay: -2.5s;
  opacity: 0;
}
.loading-21 view:nth-child(6) {
  background: #c5f0a4;
  animation-delay: -3s;
  opacity: 0;
}

@keyframes move {
  0% {
    transform: scale(1) rotate(0deg) translate3d(0, 0, 1px);
  }
  30% {
    opacity: 1;
  }
  100% {
    z-index: 10;
    transform: scale(0) rotate(360deg) translate3d(0, 0, 1px);
  }
}
</style>
